﻿<ResourceDictionary    
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:conv="clr-namespace:QuickZip.Converters"            
    xmlns:local="clr-namespace:QuickZip.UserControls"            
    xmlns:sys="clr-namespace:System;assembly=mscorlib" >

    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="pack://application:,,,/QuickZip.UserControls;component/Themes/Brushes.xaml" />
        <ResourceDictionary Source="pack://application:,,,/QuickZip.UserControls;component/Themes/Geometry.xaml" />
        <ResourceDictionary Source="pack://application:,,,/QuickZip.UserControls;component/Themes/Converters.xaml" />
    </ResourceDictionary.MergedDictionaries>


    <ControlTemplate x:Key="BaseToolbarButton" TargetType="{x:Type ButtonBase}">
        <Border x:Name="border"
                Padding="2,0"
				Background="Transparent" 
				BorderBrush="Transparent"
                BorderThickness="1"				
				SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}">
            <ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Stretch" />
        </Border>
    </ControlTemplate>

    <!--TopLevelHeaderTemplateKey-->
    <ControlTemplate x:Key="TopLevelHeaderTemplateKey" TargetType="{x:Type local:ToolbarMenuItem}">
        <Border Name="Border" Margin="0,2" Padding="1" Focusable="True" IsHitTestVisible="True" >
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition MaxHeight="11"/>
                    <RowDefinition/>
                </Grid.RowDefinitions>
                <Rectangle x:Name="UpperHighlight" Fill="#75FFFFFF" Visibility="Collapsed"/>
                <StackPanel Orientation="Horizontal" Margin="0" Grid.RowSpan="2" Background="Transparent" >
                    <Border Name="borderIcon" Padding="0,0,1,0" Margin="2,0" VerticalAlignment="Stretch">
                        <Grid>
                            <Grid.RowDefinitions>
                                <RowDefinition MaxHeight="11"/>
                                <RowDefinition/>
                            </Grid.RowDefinitions>
                            <Rectangle x:Name="iconUpperHighlight" Fill="#75FFFFFF" Visibility="Collapsed"/>                            
                            <StackPanel Orientation="Horizontal" Grid.RowSpan="2" >
                                <ContentPresenter Name="Icon" Margin="2,0" ContentSource="Icon"/>                                
                                <ContentPresenter VerticalAlignment="Center" ContentSource="Header" RecognizesAccessKey="True" Margin="0" />
                            </StackPanel>
                            <Button x:Name="buttonContent" Template="{StaticResource BaseToolbarButton}" Focusable="False"  Grid.RowSpan="2"
                                Command="{TemplateBinding Command}" 
                                Visibility="{Binding IsHeaderTogglePopup, Converter={StaticResource fbtvc}, 
                            RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type local:ToolbarMenuItem}}}"
                                />
                        </Grid>
                    </Border>
                    <Grid x:Name="gridExpander" Background="Transparent" IsHitTestVisible="True">
                        <Path DockPanel.Dock="Right" Fill="{StaticResource toolForegroundBrush}" 
                                                  Data="{StaticResource expandlArrow}" VerticalAlignment="Center" Margin="4,0" />
                    </Grid>

                    <Popup Name="Popup" Placement="Bottom" IsOpen="{TemplateBinding IsSubmenuOpen}" AllowsTransparency="True" 
                            Focusable="False" PopupAnimation="Fade"                       
                       >
                        <Border Name="SubmenuBorder" SnapsToDevicePixels="True" Background="{StaticResource WindowBackgroundBrush}"
                                    BorderBrush="{StaticResource SolidBorderBrush}" BorderThickness="1" >
                            <DockPanel>
                                <local:MultiStepSlider x:Name="mss" Orientation="Vertical" DockPanel.Dock="Left" PositionType="ptRelative"
                                           Steps="{Binding Steps, ElementName=itemHost}"
                                           Value="{Binding Path=SliderValue, 
                                                RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:ToolbarMenuItem}}, Mode=TwoWay}"
                                           Maximum="{Binding Path=SliderMaximum, 
                                                RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:ToolbarMenuItem}}, Mode=TwoWay}"
                                           Minimum="{Binding Path=SliderMinimum, 
                                                RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:ToolbarMenuItem}}, Mode=TwoWay}"
                                           
                                           Visibility="{Binding Path=IsSliderEnabled, 
                                                RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:ToolbarMenuItem}}, 
                                                Converter={StaticResource btv}, 
                                                Mode=TwoWay}"        
                                                   
                                                   />
                                <local:SliderSupportedPanel x:Name="itemHost" IsItemsHost="True" 
                                                      KeyboardNavigation.DirectionalNavigation="Cycle" />
                            </DockPanel>
                        </Border>
                    </Popup>
                </StackPanel >
            </Grid>
        </Border>
        <ControlTemplate.Triggers>
            <Trigger Property="IsSuspendingPopupAnimation" Value="true">
                <Setter TargetName="Popup" Property="PopupAnimation" Value="None"/>
            </Trigger>

            <Trigger Property="IsChecked" Value="true">
                <Setter TargetName="borderIcon" Property="Background" Value="{StaticResource HotTrackBrush}"/>
            </Trigger>

            <MultiTrigger>
                <MultiTrigger.Conditions>
                    <Condition Property="IsHeaderTogglePopup" Value="False" />
                    <Condition Property="IsHighlighted" Value="True" />
                </MultiTrigger.Conditions>
                <MultiTrigger.Setters>
                    <Setter TargetName="borderIcon" Property="Padding" Value="0"/>
                    <Setter TargetName="borderIcon" Property="BorderThickness" Value="0,0,1,0"/>
                    <Setter TargetName="borderIcon" Property="BorderBrush" Value="{StaticResource SolidBorderBrush}"/>
                </MultiTrigger.Setters>
            </MultiTrigger>

            <Trigger SourceName="buttonContent" Property="IsMouseOver" Value="True">
                <Setter Property="Visibility" TargetName="iconUpperHighlight" Value="Visible"/>
                <Setter TargetName="borderIcon" Property="Background" Value="{StaticResource HotTrackBrush}"/>
            </Trigger>

            <MultiTrigger>
                <MultiTrigger.Conditions>
                    <Condition SourceName="gridExpander" Property="IsMouseOver" Value="True" />
                    <Condition Property="IsHeaderTogglePopup" Value="False" />
                </MultiTrigger.Conditions>
                <MultiTrigger.Setters>
                    <Setter TargetName="borderIcon" Property="Background" Value="{StaticResource LightBrush}"/>
                </MultiTrigger.Setters>
            </MultiTrigger>

            <Trigger SourceName="buttonContent" Property="IsPressed" Value="True">
                <Setter TargetName="borderIcon" Property="Background" Value="{StaticResource PressedBrush}"/>
            </Trigger>

            <Trigger Property="IsHighlighted" Value="true">
                <Setter TargetName="Border" Property="BorderBrush" Value="{StaticResource SolidBorderBrush}"/>
                <Setter TargetName="Border" Property="Background" Value="{StaticResource HotTrackBrush}"/>
                <Setter TargetName="Border" Property="Padding" Value="0"/>
                <Setter TargetName="Border" Property="BorderThickness" Value="1"/>
                <Setter Property="Visibility" TargetName="UpperHighlight" Value="Visible"/>
            </Trigger>

            <Trigger SourceName="Popup" Property="Popup.AllowsTransparency" Value="True">
                <Setter TargetName="SubmenuBorder" Property="CornerRadius" Value="0,0,4,4"/>
                <Setter TargetName="SubmenuBorder" Property="Padding" Value="0,0,0,3"/>
            </Trigger>
            <Trigger Property="IsEnabled" Value="False">
                <Setter Property="Foreground" Value="{StaticResource DisabledForegroundBrush}"/>
            </Trigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>
    <!--TopLevelItemTemplateKey-->
    <ControlTemplate x:Key="TopLevelItemTemplateKey" TargetType="{x:Type local:ToolbarMenuItem}">

        <Border Name="Border"  Margin="2" Padding="1"   >
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition MaxHeight="11"/>
                    <RowDefinition/>
                </Grid.RowDefinitions>
                <Rectangle x:Name="UpperHighlight" Fill="#75FFFFFF" Visibility="Collapsed"/>
                <StackPanel Orientation="Horizontal" Grid.RowSpan="2" >
                    <ContentPresenter Name="Icon" Margin="2,0" ContentSource="Icon"/>
                    <ContentPresenter VerticalAlignment="Center" ContentSource="Header" RecognizesAccessKey="True" Margin="0" />
                    <!--<ContentPresenter Margin="6,0" 
                                      VerticalAlignment="Center"  ContentSource="Header" RecognizesAccessKey="True" />-->
                </StackPanel>
            </Grid>
        </Border>

        <ControlTemplate.Triggers>
            <Trigger Property="IsHighlighted" Value="true">
                <Setter TargetName="Border" Property="BorderBrush" Value="{StaticResource NormalBorderBrush}"/>
                <Setter TargetName="Border" Property="Background" Value="{StaticResource HotTrackBrush}"/>
                <Setter TargetName="Border" Property="Padding" Value="0"/>
                <Setter TargetName="Border" Property="BorderThickness" Value="1"/>
                <Setter Property="Visibility" TargetName="UpperHighlight" Value="Visible"/>
            </Trigger>
            <Trigger Property="IsEnabled" Value="False">
                <Setter Property="Foreground" Value="{StaticResource DisabledForegroundBrush}"/>
            </Trigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>
    <!--SubmenuHeaderTemplateKey-->
    <ControlTemplate x:Key="SubmenuHeaderTemplateKey" TargetType="{x:Type local:ToolbarMenuItem}">
        <Border Name="Border" >
            <Grid Margin="0,0,5,0">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="30" SharedSizeGroup="Icon"/>
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="Auto" SharedSizeGroup="Shortcut"/>
                    <ColumnDefinition Width="13"/>
                </Grid.ColumnDefinitions>
                <ContentPresenter Name="Icon" Margin="6,0,6,0" VerticalAlignment="Center" ContentSource="Icon"/>
                <Border Background="Transparent" Grid.Column="1" >
                    <ContentPresenter Name="HeaderHost" Grid.Column="1" ContentSource="Header" 
                                  RecognizesAccessKey="True" HorizontalAlignment="Stretch" />
                </Border>
                <TextBlock x:Name="InputGestureText" Grid.Column="2" Text="{TemplateBinding InputGestureText}" Margin="5,2,2,2"
                            DockPanel.Dock="Right"/>
                <Path Grid.Column="3" HorizontalAlignment="Center" VerticalAlignment="Center" Data="M 0 0 L 0 7 L 4 3.5 Z" 
                      Fill="{StaticResource GlyphBrush}" />
                <Popup Name="Popup" Placement="Right" HorizontalOffset="-4" IsOpen="{TemplateBinding IsSubmenuOpen}" AllowsTransparency="True" 
                       Focusable="False" PopupAnimation="Fade">
                    <Border Name="SubmenuBorder" SnapsToDevicePixels="True" 
                            Background="{StaticResource WindowBackgroundBrush}" 
                            BorderBrush="{StaticResource SolidBorderBrush}" BorderThickness="1" >
                        <StackPanel IsItemsHost="True" KeyboardNavigation.DirectionalNavigation="Cycle" />
                    </Border>
                </Popup>
            </Grid>
        </Border>
        <ControlTemplate.Triggers>
            <Trigger Property="Icon" Value="{x:Null}">
                <Setter TargetName="Icon" Property="Visibility" Value="Collapsed"/>
            </Trigger>
            <Trigger Property="IsHighlighted" Value="true">
                <Setter TargetName="Border" Property="Background"
              Value="{StaticResource HotTrackBrush}"/>
            </Trigger>
            <Trigger SourceName="Popup" Property="Popup.AllowsTransparency" Value="True">
                <Setter TargetName="SubmenuBorder" Property="CornerRadius" Value="4"/>
                <Setter TargetName="SubmenuBorder" Property="Padding" Value="0,3,0,3"/>
            </Trigger>
            <Trigger Property="IsEnabled" Value="false">
                <Setter Property="Foreground" Value="{StaticResource DisabledForegroundBrush}"/>
            </Trigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>
    <!--SubmenuItemTemplateKey-->
    <ControlTemplate x:Key="SubmenuItemTemplateKey" TargetType="{x:Type local:ToolbarMenuItem}">
        <Grid MinHeight="{Binding Path=ItemHeight, 
                                  RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type MenuItem}}}"               
              >
            <Separator Visibility="{Binding Path=IsSeparator, Converter={StaticResource btv}, 
                                                RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type MenuItem}}}" />
            <Border Name="Border"  Visibility="{Binding Path=IsSeparator, Converter={StaticResource fbtvc}, 
                                                RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type MenuItem}}}"                     
                                   VerticalAlignment="Bottom" Focusable="True" IsHitTestVisible="True" Background="Transparent" 
                                   Padding="1" 
                       >
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="30" SharedSizeGroup="Icon"/>
                        <ColumnDefinition Width="*" />
                        <ColumnDefinition Width="Auto" SharedSizeGroup="Shortcut"/>
                        <ColumnDefinition Width="13"/>
                    </Grid.ColumnDefinitions>
                    <ContentPresenter Name="Icon" Margin="6,0,6,0" VerticalAlignment="Center" ContentSource="Icon"/>
                    <Border Name="Check" Width="13" Height="13" Visibility="Collapsed"
                        Margin="6,0,6,0" Background="{StaticResource NormalBrush}" BorderThickness="1"
                        BorderBrush="{StaticResource NormalBorderBrush}">
                        <Path Name="CheckMark" Width="7" Height="7"  Visibility="Hidden"  SnapsToDevicePixels="False" 
                          Stroke="{StaticResource GlyphBrush}" StrokeThickness="2" Data="M 0 0 L 7 7 M 0 7 L 7 0" />
                    </Border>
                    <ContentPresenter Name="HeaderHost" Grid.Column="1" ContentSource="Header" RecognizesAccessKey="True" HorizontalAlignment="Stretch" />
                    <TextBlock x:Name="InputGestureText" Grid.Column="2" Text="{TemplateBinding InputGestureText}" Margin="5,2,0,2" />
                </Grid>
            </Border>
        </Grid>

        <ControlTemplate.Triggers>
            <Trigger Property="Icon" Value="{x:Null}">
                <Setter TargetName="Icon" Property="Visibility" Value="Hidden"/>
            </Trigger>
            <Trigger Property="IsChecked" Value="true">
                <Setter TargetName="CheckMark" Property="Visibility" Value="Visible"/>
            </Trigger>
            <Trigger Property="IsCheckable" Value="true">
                <Setter TargetName="Check" Property="Visibility" Value="Visible"/>
                <Setter TargetName="Icon" Property="Visibility" Value="Hidden"/>
            </Trigger>
            <Trigger Property="IsHighlighted" Value="true">
                <Setter TargetName="Border" Property="BorderBrush" Value="{StaticResource NormalBorderBrush}"/>
                <Setter TargetName="Border" Property="Background" Value="{StaticResource HotTrackBrush}"/>
                <!--<Setter TargetName="Border" Property="Padding" Value="0"/>
                <Setter TargetName="Border" Property="BorderThickness" Value="1"/>-->
            </Trigger>
            <Trigger Property="IsEnabled" Value="false">
                <Setter Property="Foreground" Value="{StaticResource DisabledForegroundBrush}"/>
            </Trigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>

</ResourceDictionary>